package com.tiantianfresh.view.service.impl;

import com.tiantianfresh.model.dao.CategorygroupingMapper;
import com.tiantianfresh.model.dao.CommodityMapper;
import com.tiantianfresh.model.dao.RotationchartMapper;
import com.tiantianfresh.model.pojo.*;
import com.tiantianfresh.view.service.HomePageService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author FANGAO
 * @date 2021/11/24 - 上午 10:42
 */
@Service
public class HomePageServiceServiceImpl implements HomePageService {
    @Resource
    private CategorygroupingMapper categorygroupingMapper;
    @Resource
    private CommodityMapper commodityMapper;
    @Resource
    private RotationchartMapper rotationchartMapper;

    @Override
    public List<Categorygrouping> queryAllCategorygrouping() {
        return categorygroupingMapper.selectAll();
    }
    @Override
    public List<CommodityResult> queryAllCommodity() {
        return commodityMapper.queryAll();
    }
    @Override
    public List<Rotationchart> queryAllRotationchart(){

        return rotationchartMapper.selectAll();
    }

    @Override
    public List<CategorygroupingCommodity> queryCategorygroupingCommodity() {
        List<CategorygroupingCommodity> categorygroupingCommoditys = categorygroupingMapper.queryCategorygroupingCommodity();
            categorygroupingCommoditys.forEach(
                    categorygroupingCommodity
                            ->
                    categorygroupingCommodity.setCommodities(commodityMapper.queryCatCommodity(categorygroupingCommodity.getCrid()))
            );
        return categorygroupingCommoditys;
    }
}
